package org.jash.day7.utils;

import org.jash.day7.NewsModel;
import org.jash.day7.mvp.BasePresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

public class NewsPresenter extends BasePresenter<ConStruct.INewsView> implements ConStruct.INewsPresenter {
    private ConStruct.INewsModel model = new NewsModel();
    @Override
    public void loadTopHot() {
        disposable.add(model.getTopHot()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(res -> {
                    if (isAttach()) {
                        if (res.getCode() == 0) {
                            getWhoView().success(res.getData());
                        } else {
                            getWhoView().failure(new RuntimeException(res.getMsg()));
                        }
                    }
                }, t -> {
                    if (isAttach()) {
                        getWhoView().failure(t);
                    }
                }));
    }
}
